package com.huida.app;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author: Wangzz
 * @Version: 1.0.0
 * @CreateDate: Created in 2021/11/14 16:01
 * @UpdateDate: [dateFormat:YYYY-MM-DD][modifier][description]
 */

@Data
@AllArgsConstructor
class Basic{
    private String typeName;
}
public class TestDemoUnit {



    public static void main(String[] args) throws ParseException {
        ArrayList<Basic> basics = new ArrayList<>();
        basics.add(new Basic("气象设备"));
        basics.add(new Basic("虫情设备"));
        basics.add(new Basic("气象设备"));
        List<Basic> collect = basics.stream().filter(b -> "虫情设备".equals(b.getTypeName()))
                .collect(Collectors.toList());
        collect.forEach(System.out::println);

//        Date parse = new SimpleDateFormat("yyyy-MM-dd").parse("2018-03-02");
//
//        String storageDateStr = new SimpleDateFormat("yyyy-MM-dd").format(parse);
//        String currentTimeStr = new SimpleDateFormat("HH:mm:ss").format(new Date());
        
//        Date date = new Date();
//        System.out.println(new SimpleDateFormat("HH:mm:ss").format(date.getTime()));
//        System.out.println(6 % 999);
//        String productBatchNo = getProductBatchNo("1");
//        System.out.println(productBatchNo);
    }
    private static String getProductBatchNo(String productCode){
        // 设置编号 生成规则：农产品编码+入库日期+三位数字自动计数。示例  rice20211011001
        String productBatchNo = "";
        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
        int countOfAgrProduct = 123; // TODO
        String suffix = getSuffix(countOfAgrProduct);
        if("0".equals(productCode)){
            return productBatchNo = ("rice" + date + suffix);
        }
        if("1".equals(productCode)){
            return productBatchNo = ("taro" + date + suffix);
        }
        if("2".equals(productCode)){
            return productBatchNo = ("potato" + date + suffix);
        }
        if("3".equals(productCode)){
            return productBatchNo = ("dendrobe" + date + suffix);
        }
        return "未知农产品编码！";
    }

    private static String getSuffix(int serialNumber){
        int result = (serialNumber % 999) + 1;
        if(result < 10){
            return "00" + result;
        }
        if(result >= 10 & result < 100){
            return "0" + result;
        }
        return "" + result;
    }
}
